import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:get/get.dart';
import 'package:mtf/R.dart';
import 'package:mtf/app/data/BankEntity.dart';
import 'package:mtf/app/modules/bank_manager_module/bank_manager_controller.dart';
import 'package:mtf/app/theme/app_boxDecoration.dart';
import 'package:mtf/app/theme/app_colors.dart';
import 'package:mtf/app/widget/AppBarLeftTitle.dart';
/**
 * GetX Template Generator - fb.com/htngu.99
 * */

class bankManagerPage extends GetView<bankManagerController> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBarLeftTitle(title: "银行卡管理"),
      body: Obx(() {
        return ListView.builder(
          shrinkWrap: true,
          itemBuilder: (context, index) {
            if (index == controller.bankList.length||controller.bankList.length==0) {
              //尾部
              return InkWell(
                onTap: () {
                  controller.clickAddBank();
                },
                child: Container(
                  margin: EdgeInsets.all(15),
                  height: 142,
                  alignment: Alignment.center,
                  decoration: whiteCardBox,
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      SvgPicture.asset(R.assetsImgIcSvgAdd,
                          width: 16, height: 16),
                      Padding(
                        padding: const EdgeInsets.all(5.0),
                        child: Text("添加银行卡"),
                      )
                    ],
                  ),
                ),
              );
            } else {
              return bankItem(controller.bankList[index]);
            }
          },
          itemCount: controller.bankList.length + 1,
        );
      }),
    );
  }

  Widget bankItem(ListBankElement bean) {
    return Container(
      width: double.infinity,
      margin: EdgeInsets.only(left: 15, right: 15, top: 20),
      padding: EdgeInsets.only(left: 15, right: 15, top: 15),
      decoration: whiteCardBox,
      child: InkWell(
        onTap: (){
          controller.reqClickChoice(bean);
        },
        child: Column(
          children: [
            Row(
              children: [
                // ClipOval(
                //     child: Image.network(
                //   "https://via.placeholder.com/24x24",
                //   height: 24,
                //   width: 24,
                // )),
                Padding(
                  padding: const EdgeInsets.symmetric(horizontal: 0),
                  child: Text(
                    bean.bankName ?? "",
                    style: TextStyle(color: c_333333, fontSize: 14),
                  ),
                ),
                Container(
                    padding: EdgeInsets.all(3),
                    decoration: BoxDecoration(
                        color: c_ebf5ff, borderRadius: BorderRadius.circular(6)),
                    child: Text(
                      "储蓄卡",
                      style: TextStyle(color: c_51a3ff, fontSize: 11),
                    ))
              ],
            ),
            Align(
              alignment: Alignment.topLeft,
              child: Padding(
                padding: const EdgeInsets.symmetric(vertical: 15),
                child: Text(bean.bankAccount ?? ""),
              ),
            ),
            Divider(
              height: 1,
            ),
            InkWell(
              onTap: (){
                showOkCancelAlertDialog(
                    context: Get.context!!,
                    title: '提示',
                    message: '确定要解除银行卡吗？',
                    cancelLabel: "取消",
                    okLabel: "确定",
                    useActionSheetForIOS: true,
                    defaultType: OkCancelAlertDefaultType.cancel)
                    .then((value) {
                      if(value.index==0){
                        controller.reqBankDelete(bean);
                      }
                  print('apple${value.index}');
                });
              },
              child: Container(
                  width: double.infinity,
                  padding: EdgeInsets.symmetric(vertical: 14),
                  alignment: Alignment.center,
                  child: Text(
                    "解除绑定",
                    style: TextStyle(color: c_999999, fontSize: 13),
                  )),
            )
          ],
        ),
      ),
    );
  }
}
